<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>命令模式</title>
</head>
<body>
    <button id="bt1">doLogin</button>
    <script>
        var btn1 = document.getElementById('btn1')

        // 动作: 命令
        let receiverObj = {
            doLogin() {
                console.log('登录')
            }
        }

        // 执行者
        var DoLoginCommand = function(receiver) {
            this.receiver = receiver
        }
        DoLoginCommand.prototype.execute = function() {
            this.receiver.doLogin()
        }
        // 生成一个执行者
        let doLoginObj = new DoLoginCommand(receiverObj)

        // 接受者
        let setCommand = function(eml, command) {
            eml.onclick = function() {
                command.execute()
            }
        }

        setCommand(bt1, doLoginObj)

    </script>
</body>
</html>